package net.cyndeline.game.defaultImpl

import net.cyndeline.game.TurnHandler
import scala.collection.immutable.Queue
import net.cyndeline.entitySystem.EntityRef

class TurnQueueHandler extends TurnHandler {
  private var queue = Queue[EntityRef]()
  
  override def contains(entity: EntityRef) = queue.contains(entity)
  
  override def add(entity: EntityRef) {
    queue = queue.enqueue(entity)
  }
  
  override def remove(entity: EntityRef) = queue = queue.filterNot(_ == entity)
  
  override def current = queue.front
  
  override def next() = {
    val atFront: (EntityRef, Queue[EntityRef]) = queue.dequeue
    queue = atFront._2.enqueue(atFront._1)
    queue.front
  }
  
  override def isEmpty = queue.isEmpty
  
}